package com.briup.jz.web.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.briup.jz.bean.Comment;
import com.briup.jz.bean.extend.ArticleExtend;
import com.briup.jz.bean.extend.CommentExtend;
import com.briup.jz.service.ICommentService;
import com.briup.jz.utils.Message;
import com.briup.jz.utils.MessageUtil;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;

@RestController
@RequestMapping("/comment")
@Api(description="栏目管理")//注解，描述这个类
public class CommentController {
	
	//
	@Autowired
	private ICommentService commentService;
	
	@GetMapping("/findAll")
	@ApiOperation("查询所有栏目信息")//注解，描述方法
	public Message findAll(){
		return MessageUtil.success(commentService.findAll());
	}
	
	@GetMapping("/findById")
	@ApiOperation("通过id查询记录")//注解，描述方法
	@ApiImplicitParam(name="id",value="栏目id",dataType="long",paramType="query",required=true)	//对参数的描述
	public Message findById(Long id) {
		return MessageUtil.success(commentService.findById(id));
	}
	
    @ApiOperation(value = "分页查询")
    @GetMapping("pageQuery")
    public Message pageQuery(int page, int pageSize,String keywords){
        List<Comment> list = commentService.pageQuery(page,pageSize,keywords);
        return MessageUtil.success(list);
    }
	
	@PostMapping("/saveOrUpdate")
	//value在只有一个属性时可以不写
	@ApiOperation(value="插入或者更新",notes="有id就更新，无id就插入")//注解，描述方法
	public Message saveOrUpdate(Comment c1) {
		commentService.saveOrUpdate(c1);
		return MessageUtil.success("操作成功");
	}
	
	@DeleteMapping("/delete")
	@ApiOperation("根据id删除记录")//注解，描述方法
	@ApiImplicitParam(name="id",value="栏目id",dataType="long",paramType="query",required=true)
	public Message delete(Long id) {
		commentService.delete(id);
		return MessageUtil.success("删除成功");
	}
}